package com.zhanghu.backendZray.converter;

import com.zhanghu.backendZray.pojo.entity.File;
import com.zhanghu.backendZray.pojo.request.file.FileRequest;
import com.zhanghu.backendZray.pojo.vo.FileVo;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author ZhangDong
 * @date 2024/8/19 9:18
 */
@Component
public class FileConverter extends Converter<FileRequest, File, FileVo> {

    protected FileConverter() {
        super(FileConverter::request2Entity, FileConverter::file2Vo);
    }

    private static File request2Entity(FileRequest request) {
        File file = new File();

        return file;
    }

    private static FileVo file2Vo(File file) {
        FileVo fileVo = new FileVo();
        fileVo.setId(file.getId());
        fileVo.setName(file.getName());
        fileVo.setSize(file.getSize());
        fileVo.setUrl(Arrays.asList(file.getUrl()));
        fileVo.setPreviewUrl(file.getPreviewUrl());
        fileVo.setCreateTime(file.getCreateTime());
        return fileVo;
    }
}
